#ifndef    M_Code_EXCEPTION_H
#define   M_Code_EXCEPTION_H

#include <wx/string.h>
#include <wx/log.h>
#include "globals.h"
#include <csignal>

class M_Code_Exception {
  public:
    M_Code_Exception( const wxString& msg, const wxString& file, int line );
    virtual ~M_Code_Exception();
    void ShowErrorMessage( bool safe = true );
    wxString Message;
    wxString File;
    int Line;
};

#define m_Throw(message)   throw M_Code_Exception(message, cbC2U(__FILE__), __LINE__)
#define DIE()   kill(getpid(), SIGTERM)
#define cbAssertMessage(expr) \
  wxString err; \
  err.Printf(_T("Assertion failed in %s at %s:%d.\n\n%s"), cbC2U(__PRETTY_FUNCTION__).wx_str(), cbC2U(__FILE__).c_str(), __LINE__, cbC2U(#expr).c_str());

#define cbAssertNonFatal(expr) \
  if (!(expr)) { \
    cbAssertMessage(expr); \
    wxSafeShowMessage(_T("Assertion error"), err); \
  }

#define cbAssert(expr) \
  if (!(expr)) { \
    cbAssertMessage(expr); \
    wxSafeShowMessage(_T("Fatal assertion error"), err); \
    DIE(); \
  }

#endif
